from ..models.base_model import BaseModel
from ..models.classinfo import ClassInfo
from ..models.grade import Grade
from ..models.semester import Semester
from django.contrib.auth.models import User
from django.db import models

# 报表系统
class Report(BaseModel):
    """报表模型"""
    REPORT_TYPE_CHOICES = [
        ('daily', '日报'),
        ('weekly', '周报'),
        ('monthly', '月报'),
        ('semester', '学期报'),
    ]

    report_type = models.CharField(max_length=20, choices=REPORT_TYPE_CHOICES, verbose_name="报表类型")
    start_date = models.DateField(verbose_name="开始日期")
    end_date = models.DateField(verbose_name="结束日期")
    class_id = models.ForeignKey(ClassInfo, on_delete=models.CASCADE, null=True, blank=True, related_name='reports', verbose_name="班级")
    grade = models.ForeignKey(Grade, on_delete=models.CASCADE, null=True, blank=True, related_name='reports', verbose_name="年级")
    semester = models.ForeignKey(Semester, on_delete=models.CASCADE, related_name='reports', verbose_name="学期")
    created_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='created_reports', verbose_name="创建人")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    report_file = models.FileField(upload_to='reports/', blank=True, null=True, verbose_name="报表文件")
    is_generated = models.BooleanField(default=False, verbose_name="是否已生成")

    def __str__(self):
        return f"{self.get_report_type_display()} - {self.start_date} 至 {self.end_date}"

    class Meta:
        verbose_name = "报表"
        verbose_name_plural = "报表"